package org.tity.test.dao;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.tity.sql.dao.DAO;
import org.tity.sql.data.RcdSet;

@RestController
@RequestMapping(value="/userx")
public class UserXController {

	@Autowired
	private DAO dao;
	
	@RequestMapping(value="/create")
	public String create(HttpServletRequest request) {
		String acount=request.getParameter("acount");
		String passwd=request.getParameter("passwd");
		dao.insert("sys_user").set("account", acount).set("password",passwd).set("id",dao.getSnowflakeId()).execute();
		return "suc";
	}
	
	@RequestMapping(value="/delete")
	public String delete(HttpServletRequest request) {
		String id=request.getParameter("id");
		dao.execute("delete from sys_user where id=?",id);
		return "suc";
	}
	
	@RequestMapping(value="/update")
	public String update(HttpServletRequest request) {
		
		String acount=request.getParameter("acount");
		String passwd=request.getParameter("passwd");
		String id=request.getParameter("id");
		
		dao.update("sys_user").setIf("account", acount).setIf("password",passwd).where().and("id=?",id).topExecutable().execute();
		return "";
	}
	
	@RequestMapping(value="/list")
	public String list(HttpServletRequest request) {
		RcdSet rs=dao.query("select concat(id,'') id,account from sys_user u");
		return  rs.toJSONArrayWithJSONObject().toJSONString();
	}
	
	
	
	
}
